package cn.tedu.lbs.basic.web.rpc;

import cn.tedu.lbs.basic.api.BasicApi;
import cn.tedu.lbs.basic.web.service.AdminService;
import cn.tedu.lbs.basic.web.service.UserGroupService;
import cn.tedu.lbs.basic.web.service.UserService;
import com.tarena.lbs.pojo.basic.dto.AdminDTO;
import com.tarena.lbs.pojo.basic.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@DubboService
@Component
@Slf4j
public class BasicApiImpl implements BasicApi {
    //rpc实现 service入口之一
    @Autowired
    private AdminService adminService;
    @Autowired
    private UserGroupService userGroupService;
    @Autowired
    private UserService userService;
    @Override
    public AdminDTO getAdminDetail(Integer id) {
        try{
            return adminService.adminDetail(id);
        }catch (Exception e){
            log.error("远程调用失败",e);
        }
        return null;
    }

    @Override
    public List<Integer> getUserGroupIds(Integer userId, Integer businessId) {
        List<Integer> groupIds=null;
        try{
            groupIds=userGroupService.getUserGroupIds(userId,businessId);
        }catch (Exception e){
            log.error("查询用户人群列表失败 查询商家:{},查询用户:{}",businessId,userId,e);
        }
        return groupIds;
    }

    @Override
    public UserDTO userDetail(Integer userId) {
        UserDTO userDTO=null;
        try {
            userDTO=userService.detail(userId);
        } catch (Exception e) {
            log.error("查询用户详情失败,userId:{}",userId,e);
        }
        return userDTO;
    }
}
